<template>
  <GlobalPopup ref="globalPopup" @confirm="onConfirm" @cancel="onCancel" />
</template>

<script setup>
	import { ref, onMounted } from 'vue'
	import websocketService from '@/utils/websocket.js'
	import { TokenManager } from '@/utils/token.js'
	
	const globalPopup = ref(null)
	
	const onConfirm = () => {
	  console.log('Confirmed')
	}
	
	const onCancel = () => {
	  console.log('Cancelled')
	}
	
	// 应用启动时初始化WebSocket连接
	onMounted(() => {
		// 获取访问令牌
		const token = TokenManager.getAccessToken()
		if (token) {
			// 连接WebSocket
			websocketService.connect(token)
				.then(() => {
					console.log('WebSocket连接成功')
				})
				.catch(error => {
					console.error('WebSocket连接失败:', error)
				})
		} else {
			console.log('未登录，跳过WebSocket连接')
		}
	})
	
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "uview-plus/index.scss";
	
	/* 字体文件 */
	@font-face {
	  font-family: 'SourceHanSansSC';
	  src: url('@/static/font/SourceHanSansSC-Medium.otf') format('truetype');
	  font-weight: 500;
	}
	/* 字体文件 */
	@font-face {
	  font-family: 'SourceHanSansSC';
	  src: url('@/static/font/SourceHanSansCN-Light.otf') format('truetype');
	  font-weight: 400;
	}
	*{
		margin: 0;
		scrollbar-width: none;
		-ms-overflow-style: none;
		font-family: SourceHanSansSC;
	}
	.syl *{
		font-weight: 400;
	}
	
	.common-box {
		background-color: #fff;
		height: calc(100vh - var(--tabbar-height, 160rpx));
	}
	
	/* 定义 tabbar 高度变量 */
	.tabbar-common {
	  --tabbar-height: 160rpx;
	  height: var(--tabbar-height);
	}
	.btn-primary{
		height: 97.67rpx;
		border-radius: 26.16rpx;
		background: linear-gradient(90deg, rgba(12, 193, 155, 1) 0%, rgba(91, 220, 222, 1) 34.03%, rgba(5, 145, 198, 1) 65.97%, rgba(2, 120, 220, 1) 100%);
		font-size: 31.4rpx;
		line-height: 97.67rpx;
		color: rgba(255, 255, 255, 1);
		text-align: center;
	}
	
</style>